Ext.define('planner.view.developer.Developers', {
	extend: 'Ext.view.View', 
	alias : 'widget.Developers',
	title: 'Developers',
	itemSelector: 'div.thumb-wrap',
	requires: [
		'planner.store.Users',
	],
	listeners: {
		render: function(v) {
			var me = this;
			v.dragZone = Ext.create('Ext.dd.DragZone', v.getEl(), {
				getDragData: function(e) {
					var sourceEl = e.getTarget(v.itemSelector, 10), d;
					if (sourceEl) {
						console.log(sourceEl + ', data=' + v.getRecord(sourceEl).data.name);
						d = sourceEl.cloneNode(true);
						d.id = Ext.id();
						return v.dragData = {
							sourceEl: sourceEl,
							repairXY: Ext.fly(sourceEl).getXY(),
							ddel: d,
							blockData: v.getRecord(sourceEl)
						};
					}
				},
				getRepairXY: function() {
					return this.dragData.repairXY;
				}
			});

			this.dropZone = new Ext.dd.DropZone(this.getEl(), {
				getTargetFromEvent: function(e) {
					return e.getTarget('.thumb-wrap');
				},
        		onNodeDrop : function(target, dd, e, data) {
        			console.log(data.blockData.self.getName());
					var r = me.getRecord(target);
					console.log('CommonDiagramm onNodeDrop type=' + data.blockData.get('name') + ', ' + target + ', ' + r.get('name'));
        			if(data.blockData.self.getName() == 'planner.model.Jobs')
						me.fireEvent('linkDeveloperToJob', me, r, data.blockData);
        			else if(data.blockData.self.getName() == 'planner.model.Users')
						me.fireEvent('linkDeveloperToParent', me, r, data.blockData);
					return true;
				}
			});
			this.dropZone.removeFromGroup('g1');
		}
	},
	initComponent: function(arguments) {
		var me = this;

		var userTpl = new Ext.XTemplate(
		    '<tpl for=".">',
		        '<div style="margin-bottom: 10px;" class="thumb-wrap">',
		          '<img src="images/user-info.png" />',
		          '<br/><span>{id}({parent})-{name}</span>',
		          	'<div>Jobs: ',
			    		'<tpl for="jobs">',
			    			'<span>{name},</span>',
			    		'</tpl>',
		    		'</div>',
		        '</div>',
		    '</tpl>'
		);
		me.tpl = userTpl;
		me.store = Ext.create('planner.store.Users');
		this.callParent(arguments);
	}
}); 
